import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/util/toast_util.dart';
import 'package:flutter_ncsjqz_getx/widget/app_bar_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/gradient_button.dart';
import 'package:flutter_ncsjqz_getx/widget/ink_widget.dart';
import 'package:get/get.dart';

import '../order_view.dart';
import 'cancel_order_logic.dart';

/// 取先订单
class CancelOrderPage extends StatefulWidget {
  OrderModel? orderModel;
  CancelOrderPage({this.orderModel});
  @override
  _CancelOrderPageState createState() => _CancelOrderPageState();
}

class _CancelOrderPageState extends State<CancelOrderPage> {
  final CancelOrderLogic logic = Get.put(CancelOrderLogic());
  String img = "https://00.minipic.eastday.com/20190404/20190404154247_ecec9b6976420dc8daea8abfe6fae7e9_3.jpeg";

  @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: appBarWidget(title: "申请退款"),
        body: Container(
          padding: EdgeInsets.all(15),
          child: ListView(
            padding: EdgeInsets.all(0),
            children: [
              InkWell(
                child: Container(
                  width: Get.width,
                  padding: EdgeInsets.all(15),
                  margin: EdgeInsets.only(bottom: 5),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10),
                    boxShadow: [
                      BoxShadow(
                          color: Colors.grey.shade300,
                          blurRadius: 3,
                          spreadRadius: 3
                      ),
                    ],
                  ),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Row(
                        children: [
                          InkWidget.imgNet("${widget.orderModel!.img}",width: 125,height: 125,fit: BoxFit.cover,borderRadius: BorderRadius.circular(5)),
                          Container(
                            width: Get.width - 125 - 60,
                            height: 125,
                            padding: EdgeInsets.only(left: 10),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                InkWidget.title("${widget.orderModel!.title}",maxLines: 2,fonSize: 18),

                                Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    InkWidget.text("${widget.orderModel!.sku}  数量：${widget.orderModel!.count}",maxLines: 2,fonSize: 14,color: Colors.grey),
                                    InkWidget.title("￥${widget.orderModel!.price}",color: Colors.red,fonSize: 18),
                                  ],
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
                onTap: (){
                  toast("查看商品详情");
                },
              ),

              Text("\n退款理由\n"),

              Container(
                width: Get.width,
                height: Get.height * 0.25,
                padding: EdgeInsets.fromLTRB(15, 0, 15, 5),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.grey.shade200,
                        spreadRadius: 2,
                        blurRadius: 5,
                      ),
                    ]
                ),
                child: TextField(
                  maxLength: 100,
                  maxLines: 999,
                  controller: logic.textEditingController,
                  decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: "请输入退款理由, 100字"
                  ),
                )
              ),
            ],
          ),
        ),
        bottomNavigationBar: Container(
          width: Get.width,
          height: 60,
          color: Colors.white,
          padding: EdgeInsets.symmetric(horizontal: 15),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                children: [
                  Text("退款金额：",style: TextStyle(fontSize: 16,color: Colors.green),),
                  Text("￥${widget.orderModel!.count! * widget.orderModel!.price!}",style: TextStyle(fontSize: 18,color: Colors.green),),
                ],
              ),

              gradientButton("提交",circular: 40,onTap: () async{
                logic.applyOrderRefund(widget.orderModel!.id,widget.orderModel!.price,widget.orderModel!.status);
              }),
            ],
          ),
        ),
      );
    }

  @override
  void dispose() {
    Get.delete<CancelOrderLogic>();
    super.dispose();
  }
}